<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/adminlogin.css">
</head>
<body>

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label" style="margin-top: 125px">添加</label>
        <label class="layui-form-label"  style="margin-top: 105px"></label>
        <div class="layui-input-block">

            <input type="text" name="title1" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            <input type="text" name="title2" lay-verify="title" autocomplete="off" placeholder="请输入类型" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button><br>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >删除</label>
        <div class="layui-input-block">
            <input type="text" name="title3" lay-verify="title" autocomplete="off" placeholder="请输入ID" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo2">删除</button>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">修改</label>
        <label class="layui-form-label"></label>
        <div class="layui-input-block">

            <input type="text" name="title4" lay-verify="title" autocomplete="off" placeholder="请输入ID" class="layui-input">
            <input type="text" name="title5" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            <input type="text" name="title6" lay-verify="title" autocomplete="off" placeholder="请输入类型" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo3">立即修改</button><br>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">查询</label>
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="text" name="title7" lay-verify="title" autocomplete="off" placeholder="请输入ID" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo4">立即查询</button><br>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo5">全部查询</button><br>
        </div>
    </div>
</form>
<script src="${pageContext.request.contextPath}/static/layui/layui.js" charset="utf-8"></script>
</script>
<script>

        // 登陆事件
        $('#loginBtn').click(function () {
            login();
        });
        // 注册事件
        $('#loginRegister').click(function () {
            register();
        });

     /*   var params = {};
        var title = $('#title1').val();
        var title1 = $('#title2').val();
        params.title = title;
        params.title1 = title1;*/
        //switch 是 lay-skin的
        //想要开启监听模块  layui.use 中的var layer的值必须也要打开 需填写 里面需要的值 form = layui.form
        //监听提交
        form.on('submit(demo1)',function (data){
            // alert("123")
           /*   layer.alert(JSON.stringify(data.field),{
                 title: '最终提交信息'
             })*/
            alert(JSON.stringify(data));
            $.ajax({
                <%--//${pageContext.requst.contextPath}上下文路径  跳转路径--%>
                // 传入当前的值
                type:"post",
                data:data.field,
                url:"${pageContext.request.contextPath}/user/addUser",
                success:function (d){
                    layer.alert(JSON.stringify(d))
                    if(d.code==0){
                        //登录页面
                        window.location = "${pageContext.request.contextPath}/login.jsp";
                    }
                }
            })
            return false;
        })
        //监听删除
        form.on('submit(demo2)',function (data){
            // alert("123")
            /*   layer.alert(JSON.stringify(data.field),{
                  title: '最终提交信息'
              })*/
            // var i = data.field;
            // alert(i[3])
            // alert(JSON.stringify(data.field))
            var upduser = {};
            upduser.title3 = data.field.title3;
            alert(JSON.stringify(data.field.title3));
            $.ajax({
                <%--//${pageContext.requst.contextPath}上下文路径  跳转路径--%>
                // 传入当前的值
                type:"post",
                data:upduser,
                url:"${pageContext.request.contextPath}/user/delUser",
                success:function (d){
                    layer.alert(JSON.stringify(d))
                    if(d.code==0){
                        //登录页面
                        window.location = "${pageContext.request.contextPath}/login.jsp";
                    }
                }
            })
            return false;
        })
        //监听修改
        form.on('submit(demo3)',function (data){
            // alert("123")
            /*   layer.alert(JSON.stringify(data.field),{
                  title: '最终提交信息'
              })*/
               var upduser = {};
               upduser.title4 = data.field.title4;
                upduser.title5 = data.field.title5;
                upduser.title6 = data.field.title6;
                alert(JSON.stringify(upduser))
            $.ajax({
                <%--//${pageContext.requst.contextPath}上下文路径  跳转路径--%>
                // 传入当前的值
                type:"post",
                data:upduser,
                url:"${pageContext.request.contextPath}/user/updUser",
                success:function (d){
                    layer.alert(JSON.stringify(d))
                    if(d.code==0){
                        //登录页面
                        window.location = "${pageContext.request.contextPath}/login.jsp";
                    }
                }
            })
            return false;
        })
        //监听查询
        form.on('submit(demo4)',function (data){
            // alert("123")
            /*   layer.alert(JSON.stringify(data.field),{
                  title: '最终提交信息'
              })*/
            var upduser = {};
            upduser.title7 = data.field.title7;
            alert(data.field.title7)
            $.ajax({
                <%--//${pageContext.requst.contextPath}上下文路径  跳转路径--%>
                // 传入当前的值
                type:"post",
                data: upduser,
                url:"${pageContext.request.contextPath}/user/selectUser",
                success:function (d){
                    layer.alert(JSON.stringify(d))
                    if(d.code==0){
                        //登录页面
                        window.location = "${pageContext.request.contextPath}/homepage.jsp";
                    }
                }
            })
            return false;
        })
        //监听全部查询
        form.on('submit(demo5)',function (){
            // alert("123")
            /*   layer.alert(JSON.stringify(data.field),{
                  title: '最终提交信息'
              })*/
                $.ajax({
                <%--//${pageContext.requst.contextPath}上下文路径  跳转路径--%>
                // 传入当前的值
                    type:"post",
                    data: null,
                    url:"${pageContext.request.contextPath}/user/selectAll",
                success:function (d){
                    layer.alert(JSON.stringify(d))
                    if(d.code==0){
                        //登录页面
                        window.location = "${pageContext.request.contextPath}/login.jsp";
                    }
                }
            })
            return false;
        })






</script>

</body>